#include "NetworkCommonFunction.h"
#include "CommProgram.h"

#include <QDebug>

bool DeviceControlHandler(int socket, int commandLength)
{
	qDebug()<<"Receive device control handler";

	int light;
	if(!getFourByte(socket, light))
	{
		qDebug()<<"Get sub direction error";
		return false;
	}
	char convertNum;
	qDebug()<<light;
	switch(light)
	{
	case 1:
		convertNum = '1';
		break;
	case 2:
		convertNum = '2';
		break;
	case 3:
		convertNum = '3';
		break;
	case 4:
		convertNum = '4';
		break;
	case 5:
		convertNum = '5';
		break;
	case 6:
		convertNum = '6';
		break;
	default:
		return false;
	}

	//	char* convertNum = QString::number(light).toLocal8Bit().data();
	//	qDebug()<<"Control device num:"<<*convertNum;

	bool deviceSwitch;
	if(!getFourByte(socket,deviceSwitch))
	{
		qDebug()<<"Get switch error.";
		return false;
	}
	InitialLight(&convertNum,deviceSwitch );

	return true;
}
